#include "StdAfx.h"
#include "Frustum.h"

VAMPIRE_NAMESPACE_BEGIN


Frustum::Frustum( const TString& name, const Real& width /*= 800.0f*/, const Real& height /*= 600.0f*/, const Real& nearClipDist /*= 1.0f*/, const Real& farClipDist /*= 1000.0f*/, const Real& fov /*= D3DX_PI * 0.5f*/ )
: MovableObject(name), mWidth(width), mHeight(height), mNearClipDistance(nearClipDist), mFarClipDistance(farClipDist), mFOV(fov), mProjectionMatrix(), mAspectRatio(mWidth / mHeight)
{
	projectionTransform();
}

const Real& Frustum::getNearClipDistance() const
{
	return mNearClipDistance;
}

void Frustum::setNearClipDistance( const Real& nearClipDistance )
{
	mNearClipDistance = nearClipDistance;
	projectionTransform();
}

const Real& Frustum::getFarClipDistance() const
{
	return mFarClipDistance;
}

void Frustum::setFarClipDistance( const Real& farClipDistance )
{
	mFarClipDistance = farClipDistance;
	projectionTransform();
}

const Real& Frustum::getFOV() const
{
	return mFOV;
}

void Frustum::setFOV( const Real& fov )
{
	mFOV = fov;
	projectionTransform();
}

void Frustum::projectionTransform()
{
	D3DXMatrixPerspectiveFovLH(
		&(mProjectionMatrix.mData),
		mFOV,
		mAspectRatio,
		mNearClipDistance,
		mFarClipDistance);
	gpDevice->SetTransform(D3DTS_PROJECTION, &(mProjectionMatrix.mData));
}

VAMPIRE_NAMESPACE_END
